package com.nitty.cash.loop.ui.factory

import android.util.SparseArray
import androidx.fragment.app.Fragment
import com.nitty.cash.loop.base.BaseFragment
import com.nitty.cash.loop.ui.fragment.GuidePageFragment

/**
 * NittyCash
 * @Author wwdeng
 * @CreateTime: 2024/11/28 13:45
 * @Annotation：引导页
 */
class GuideFactory {

    companion object {
        private val fragments by lazy { SparseArray<BaseFragment?>() }
        @JvmStatic
        fun create(position: Int): Fragment {
            var fragment = fragments.get(position)
            if (fragment == null) {
                fragment = when (position) {
                    0 -> GuidePageFragment(0)
                    1 -> GuidePageFragment(1)
                    else -> GuidePageFragment(2)
                }
                fragments.put(position, fragment)
            }
            return fragment
        }

        @JvmStatic
        fun clear() {
            fragments.clear()
        }
    }
}